package yanc.app

import grails.transaction.Transactional
import org.springframework.beans.factory.annotation.Value

@Transactional
class NewsService {
    @Value('${phoneService.ul}')
    protected String URLS

    def del(String id) {
        def news = News.findById(id)
        news.delete()
    }

    def add(News news) {
        news.id = new Date().format("yyyyMMddHHmmss")
        news.createDate = new Date()
        news.modifyDate = new Date()
//        news.save()
        if (!news.save()) {
            news.errors.allErrors.each {
                println it
            }
        }
    }

    def refresh(News news) {
        news.modifyDate = new Date()
        news.save()
        if (!news.save()) {
            news.errors.allErrors.each {
                println it
            }
        }
    }

    def String getPath(String path) {
        println URLS + path
        return URLS + path
    }
}
